/**
 * Created with IntelliJ IDEA.
 * Description:0~n-1中缺失的数字
 * User: bjc
 * Date: 2025-11-17
 * Time: 14:25
 */
public class Test08_takeAttendance {
    public int takeAttendance(int[] records) {
        int left = 0, right = records.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (records[mid] == mid)
                left = mid + 1;
            else
                right = mid;
        }
        return records[left] == left ? left + 1 : left;
    }
    //暴力
    public int takeAttendance1(int[] records) {
        int i = 0;
        for(i = 0;i<records.length;i++){
            if(records[i] != i) return i;
        }
        return i;
    }
    public int takeAttendance2(int[] records) {
        int i = 0;
        for(;i<records.length;i++){
            int ret = records[i] ^ i;
            if(ret != 0) return i;
        }
        return i;
    }
}
